﻿

using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;


public class BLL_tbl_users
{
    public BLL_tbl_users()
    {

    }

    public List<tbl_users> select(int USER_CODE)
    {
        DAL_tbl_users dal = new DAL_tbl_users();
        return dal.select(USER_CODE);
    }

    public List<tbl_users> selectAll()
    {
        DAL_tbl_users dal = new DAL_tbl_users();
        return dal.selectAll();
    }

    public DataTable selectAllForGrid()
    {
        DAL_tbl_users dal = new DAL_tbl_users();
        return dal.selectAllForGrid();
    }

    public bool insert(tbl_users tbl)
    {
        DAL_tbl_users dal = new DAL_tbl_users();
        int i = 0;
        i = dal.insert(
            tbl.USER_CODE
, tbl.USER_NAME
, tbl.USER_PASSWORD
, tbl.USER_TYPE_ID
, tbl.IS_ACTIVE
, tbl.CREATED_BY
, tbl.CREATED_DATE
        );

        return Convert.ToBoolean(i);
    }


    public bool update(tbl_users tbl)
    {
        DAL_tbl_users dal = new DAL_tbl_users();
        int i = 0;
        i = dal.update(
            tbl.USER_CODE
, tbl.USER_NAME
, tbl.USER_PASSWORD
, tbl.USER_TYPE_ID
, tbl.IS_ACTIVE
, tbl.UPDATED_BY
, tbl.UPDATED_DATE
            );

        return Convert.ToBoolean(i);
    }


    public bool delete(tbl_users tbl)
    {
        DAL_tbl_users dal = new DAL_tbl_users();
        int i = 0;
        i = dal.delete(
                tbl.USER_CODE
        );

        return Convert.ToBoolean(i);
    }

    public int changePassword(String USER_NAME, string USER_OLD_PASSWORD, String USER_NEW_PASSWORD)
    {
        String UPDATED_BY = HttpContext.Current.User.Identity.Name;
        DateTime UPDATED_DATE = DateTime.Now;
        int i = 0;
        DAL_tbl_users dll = new DAL_tbl_users();
        i = dll.changePassword(USER_NAME, USER_OLD_PASSWORD, USER_NEW_PASSWORD, UPDATED_BY, UPDATED_DATE);
        return i;
    }

    public int validateUser(String USER_NAME, String USER_PASSWORD)
    {
        DAL_tbl_users dll = new DAL_tbl_users();
        return dll.validateUser(USER_NAME, USER_PASSWORD);
    }

}

